
using System;
using System.Collections.Generic;

namespace stefc.geo.lib
{
	public static class MathUtil
	{
		public static double ToRadiant( double d )
    	{
			   return d / 180.0d * Math.PI;
    	}

    	public static double ToDegree( double r )
    	{
        	return r * 180.0d / Math.PI;
    	}
		
		public static double YardToMeter(double yd)
		{
			return yd *0.9144d;
		}
		
		public static double MileToMeter(double mi)
		{
			return mi * 1609.344d;
		}

		public static Cartesian PolarToCartesian(double angle, double distance)
		{
			return new Cartesian(
				Math.Cos(angle)*distance, Math.Sin(angle)*distance);
		}
		
		public static Cartesian PolarToCartesian(Polar coord)
		{
			return MathUtil.PolarToCartesian(coord.Angle,coord.Distance);
		}
		
		public static Polar CartesianToPolar(double x, double y)
		{
			return new Polar(Math.Atan2(y,x), Math.Sqrt(x*x+y*y));
		}
		
		public static Polar CartesianToPolar(Cartesian coord)
		{
			return MathUtil.CartesianToPolar(coord.X,coord.Y);
		}
		
		public static IEnumerable<double> IterateAngle(int sectors)
		{
			for(double angle=0.0d; angle<(2*Math.PI); angle += (2*Math.PI)/sectors)
				yield return angle;
		}			

	}
}
